<!--
  运营-招聘管理-【招聘企业】
 -->
<template>
  <div class="app-container hire-company-page">
    <!-- 搜索工作栏 -->
    <el-form
      ref="queryForm"
      :model="queryParams"
      size="small"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="企业状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择企业状态"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in companyStatus"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <!-- todo 排序方式还没有联调 -->
      <el-form-item label="排序方式" prop="rangType">
        <el-select
          v-model="queryParams.rangType"
          placeholder="选择排序方式"
          clearable
          size="small"
        >
          <!-- 1 按企业热度排序， 2 按最近登录时间排序，3 发布职位数量由高到低， 4 发布职位数量由低到高 -->
          <el-option label="按企业热度排序" value="1" />
          <el-option label="按最近登录时间排序" value="2" />
          <el-option label="发布职位数量由高到低" value="3" />
          <el-option label="发布职位数量由低到高" value="4" />
        </el-select>
      </el-form-item>
      <el-form-item label="企业名称" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          placeholder="请输入企业名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否热门企业置顶" class="choose-top-box">
        <el-select
          v-model="setTopParams.isHot"
          size="small"
          clearable
          style="width: 200px"
          placeholder="请选择"
        >
          <el-option label="不限" value="" />
          <el-option label="是" :value="1" />
          <el-option label="否" :value="0" />
        </el-select>
      </el-form-item>
      <el-form-item label="是否最新企业置顶" class="choose-top-box">
        <el-select
          v-model="setTopParams.isNew"
          size="small"
          clearable
          style="width: 200px"
          placeholder="请选择"
        >
          <el-option label="不限" value="" />
          <el-option label="是" :value="1" />
          <el-option label="否" :value="0" />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="是否职位列表置顶" class="choose-top-box">
        <el-select
          v-model="queryParams.status"
          size="small"
          clearable
          style="width: 200px"
          placeholder="请选择"
        >
          <el-option label="不限" value="" />
          <el-option label="是" value="1" />
          <el-option label="否" value="0" />
        </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        <el-button
          type="primary"
          icon="el-icon-search"
          @click="handleQuery"
        >搜索</el-button>
        <el-button
          v-if="isSuperAdmin"
          type="primary"
          @click="exportData"
        >导出企业信息</el-button>
      </el-form-item>
    </el-form>
    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="6">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
        <el-button
          v-if="isSuperAdmin"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handlesetTopSorting"
        >企业置顶排序</el-button>
      </el-col>
    </el-row>
    <!-- 列表 -->
    <el-table v-loading="loading" :data="list">
      <el-table-column label="序号" type="index" />
      <el-table-column
        label="企业信息"
        align="center"
        prop="companyLogo"
        width="550"
      >
        <template slot-scope="scope">
          <el-row :gutter="14">
            <el-col :span="10">
              <Thumbnail
                :url="scope.row.companyLogo"
                :list="[scope.row.companyLogo]"
                :size="126"
              />
            </el-col>
            <el-col :span="14">
              <div class="row1">
                <span
                  class="company-name hight-light"
                  @click="reviewDetail(scope.row)"
                >{{ scope.row.companyName }}</span>
                <img
                  v-if="Number(scope.row.topStatus) === 1"
                  src="../../../assets/images/topStatus.png"
                  style="height: 18px"
                  alt=""
                  srcset=""
                >
              </div>
              <div class="company-name" style="margin-bottom: 10px">
                最近登录：{{ parseTime(scope.row.lastloginTime) || "--" }}
              </div>
              <el-row>
                <el-col
                  :span="6"
                >发布职位：<br>{{ scope.row.jobCount }}个</el-col>
                <el-col
                  :span="6"
                >应聘职位：<br>{{ scope.row.invitCount }}个</el-col>
                <el-col
                  :span="6"
                >面试邀约<br>{{ scope.row.invitedJobCount }}个</el-col>
                <!-- todo 缺少访问总数 -->
                <el-col :span="6">访问总数<br>{{ scope.row.visitCount || "--" }}个</el-col>
              </el-row>
            </el-col>
          </el-row>
        </template>
      </el-table-column>
      <!-- 企业状态应该是 '-1' 启用（发布中）， '-2' 禁用（暂停发布） -->
      <el-table-column label="企业状态" align="center" prop="status">
        <template slot-scope="scope">
          {{ Number(scope.row.status) === -1 ? "启用" : "禁用" }}
        </template>
      </el-table-column>
      <el-table-column label="企业热度" align="center" prop="companyHot">
        <template slot="header">
          <span>企业热度</span>
          <el-tooltip
            class="item"
            effect="dark"
            content="企业热度=企业介绍页点击量+企业下属所有招聘信息点击量总和+该企业简历投递数量"
            placement="top"
          >
            <i class="el-icon-warning" />
          </el-tooltip>
        </template>
        <template slot-scope="scope">
          <img
            src="../../../assets/images/hot.png"
            style="height: 20px; margin-right: 10px"
          >{{ scope.row.companyHot }}
        </template>
      </el-table-column>
      <el-table-column label="操作人姓名" align="center" prop="operator" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="openEdit(scope.row)"
          >编辑</el-button>
          <el-popconfirm
            v-if="Number(scope.row.status) === -2"
            title="确定启用吗？"
            @confirm="handleUpdate(scope.row, 'status', '-1')"
          >
            <!-- 企业状态应该是 '-1' 启用（发布中）， '-2' 禁用（暂停发布） -->
            <el-button
              slot="reference"
              size="mini"
              type="text"
              icon="el-icon-edit"
            >启用</el-button>
          </el-popconfirm>
          <el-popconfirm
            v-if="Number(scope.row.status) === -1"
            title="确定禁用吗？"
            @confirm="handleUpdate(scope.row, 'status', '-2')"
          >
            <el-button
              slot="reference"
              size="mini"
              type="text"
              icon="el-icon-edit"
            >禁用</el-button>
          </el-popconfirm>
          <!-- orderNum 为0，或者null，表示没有置顶， 大于0，表示置顶 -->
          <!-- 企业状态 status 应该是 '-1' 启用（发布中）， '-2' 禁用（暂停发布） -->
          <el-popconfirm
            v-if="Number(scope.row.status) === -1"
            :title="scope.row.orderNum > 0 ? '取消在企业列表中置顶？' : '在企业列表中置顶？'"
            @confirm="handleUpdate(scope.row, 'setTopInList', 0)"
          >
            <el-button
              slot="reference"
              size="mini"
              type="text"
              icon="el-icon-edit"
            >{{ scope.row.orderNum > 0 ? '取消列表置顶':'列表置顶' }}</el-button>
          </el-popconfirm>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleSetingTopPop(scope.row)"
          >置顶设置</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 新建/编辑招聘企业信息 -->
    <el-dialog
      :title="title"
      :visible.sync="openUserDialog"
      width="80%"
      append-to-body
    >
      <p>请按企业实际情况，合理编辑内容</p>
      <p style="font-size: 24px; font-weight: bold">企业信息</p>
      <el-form
        ref="companyForm"
        :model="companyForm"
        :rules="rules"
        label-width="150px"
      >
        <el-form-item label="企业简称" prop="companyShortName">
          <el-input
            v-model="companyForm.companyShortName"
            placeholder="请输入企业简称"
          />
        </el-form-item>
        <el-form-item label="关联企业" prop="companyId">
          <el-select
            v-model="companyForm.companyId"
            :disabled="isEdit"
            placeholder="请选择关联企业"
          >
            <el-option
              v-for="dict in authedCompanyList"
              :key="dict.id"
              :label="dict.companyName"
              :value="dict.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="企业logo" prop="companyLogo">
          <imageUpload v-model="companyForm.companyLogo" />
        </el-form-item>
        <el-form-item label="所属行业" prop="industryType">
          <el-cascader
            v-model="companyForm.industryType"
            :show-all-levels="false"
            :options="AreaOption"
            @change="businessAreaChange"
          />
        </el-form-item>
        <p style="font-size: 24px; font-weight: bold">关于我们</p>
        <el-form-item label="企业简介" prop="introduction">
          <el-input
            v-model="companyForm.introduction"
            placeholder="请输入企业简介"
            type="textarea"
            :autosize="{ minRows: 6, maxRows: 10 }"
            show-word-limit
            maxlength="5000"
          />
        </el-form-item>
        <el-form-item label="企业环境" prop="environment">
          <p>
            图片上传
            <el-tooltip
              class="item"
              effect="dark"
              content="图片最多上传20个,最大1.5M,建议图片保持统一尺寸"
              placement="top-start"
            >
              <i class="el-icon-warning-outline" style="margin: 10px" />
            </el-tooltip>
          </p>
          <imageUpload
            key="imageUpload"
            v-model="imgList"
            size-tips=",推荐图片比例为500:280"
            :limit="10"
          />
          <p>
            视频上传<el-tooltip
              class="item"
              effect="dark"
              content="视频最多上传20个,最大200M"
              placement="top-start"
            >
              <i class="el-icon-warning-outline" style="margin: 10px" />
            </el-tooltip>
          </p>
          <fileUpload
            key="fileUpload"
            v-model="videoList"
            :is-show-tip="false"
            :limit="20"
            :file-size="200"
            :only-video="true"
          />
        </el-form-item>
        <el-form-item label="企业地址" prop="companyAddress">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>填写企业地址</span>
              <el-button
                style="float: right; padding: 3px 0"
                type="text"
                @click="handleAddAddress()"
              >新增地址</el-button>
            </div>
            <div
              v-for="(item, ind) in companyForm.companyAddress"
              :key="'address' + ind"
              class="text item"
              style="margin-bottom: 14px"
            >
              <el-cascader
                v-model="item.provienAndcity"
                style="width: 200px"
                :show-all-levels="true"
                :options="provinceAndCityData"
                :props="{ value: 'label' }"
                placeholder="请选择企业所在省市"
                @change="handleCityChange(ind)"
              />
              <el-input
                v-model.trim="item.address"
                style="width: 50%; margin: 0 14px"
                maxlength="50"
                placeholder="请输入企业详细地址"
              />
              <el-button
                v-if="companyForm.companyAddress.length > 1"
                type="text"
                style="color: red"
                @click="deleteAdd(ind)"
              >删除</el-button>
            </div>
          </el-card>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitCompanyForm">提交</el-button>
        <el-button type="primary" @click="reviewCompany">预览</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 企业信息预览 -->
    <el-drawer
      title="企业信息预览"
      :visible.sync="reviewCompanyDialog"
      direction="rtl"
      size="80%"
    >
      <el-tabs v-model="activeName" type="card" @tab-click="reviewTagChange">
        <el-tab-pane
          label="pc端"
          name="1"
        ><PcReview
          ref="PcReview"
        /></el-tab-pane>
        <el-tab-pane
          label="移动端"
          name="2"
        ><WebReview
          ref="WebReview"
        /></el-tab-pane>
      </el-tabs>
    </el-drawer>
    <SetTop ref="setTop" @handleConfirm="handleSetTopConfirm" />
    <SetSortList ref="setSortList" @success="handleQuery" />
  </div>
</template>

<script>
import {
  getHireCompanyList,
  getAuthedCompanyList,
  modefyCompanyStatus,
  setCompanyTopStatus,
  getAuthedNoRecommendCompany
} from '@/api/school-admin-api/hireManage/index.js'
import { setCompanyTopInList, getCompanyRecommend } from '@/api/company-admin-api/hireManage/index.js'
import {
  updateCompany,
  getCompanyInfo,
  updateRankingStatus
} from '@/api/school-admin-api/userManage/company/index.js'
import ImageUpload from '@/components/ImageUpload'
import FileUpload from '@/components/FileUpload'
import { companyStatus, AreaOption } from '@/utils/frontDataDict.js'
import PcReview from '../components/pcReview.vue'
import WebReview from '../components/webReview.vue'
import { deepClone } from '../../../utils'
import { provinceAndCityData } from '@/utils/frontDataDict.js'
import SetTop from './../components/setTop.vue'
import SetSortList from '../components/setSortList.vue'
import { mapGetters } from 'vuex'

export default {
  name: 'Company',
  components: {
    ImageUpload,
    FileUpload,
    PcReview,
    WebReview,
    SetTop,
    SetSortList
  },
  data() {
    const checkAddress = (rule, value, callback) => {
      const companyAddress = deepClone(this.companyForm.companyAddress)
      if (Array.isArray(companyAddress) && companyAddress.length) {
        const hasEmpty = companyAddress.some((item) => {
          if (!item.province || !item.city || !item.address) {
            return true
          }
        })
        if (hasEmpty) {
          return callback(new Error('企业地址不可为空'))
        } else {
          return callback()
        }
      } else {
        return callback(new Error('企业地址不可为空'))
      }
    }
    const checkEnvironment = (rule, value, callback) => {
      if (
        this.imgList.length > 0 ||
        this.videoList.length > 0
      ) {
        return callback()
      } else {
        return callback(new Error('企业环境不可为空'))
      }
    }
    return {
      provinceAndCityData: provinceAndCityData,
      companyStatus: companyStatus,
      activeName: '1',
      reviewCompanyDialog: false, // 企业预览
      // 企业行业类型数据，二级联动
      AreaOption: AreaOption,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 总条数
      total: 0,
      // 企业管理列表
      list: [],
      // 弹出层标题
      title: '',
      dateRangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        rangType: '', // <!-- 1 按企业热度排序， 2 按最近登录时间排序，3 发布职位数量由高到低， 4 发布职位数量由低到高 -->
        // authorized/unauthorized/reject
        // authorizedStatus: 'authorized',
        status: null, // 企业上下架状态 '-1' 启用（发布中）， '-2' 禁用（暂停发布）
        companyName: ''
      },
      setTopParams: {
        isHot: '',
        isNew: ''
      },
      companyAddress: '',
      // 企业信息表
      companyForm: {
        companyId: '', // 企业id
        companyShortName: '', // 企业简称
        companyLogo: '', // 企业logo
        industryType: [], // 行业类型
        introduction: '', // 企业简介
        environment: '', // 企业环境，图片、视频
        companyAddress: [] // 企业地址
      },
      videoList: '', // 企业环境视频
      imgList: '', // 企业环境图片
      // 表单校验
      rules: {
        companyId: [
          { required: true, message: '关联企业不能为空', trigger: 'changes' }
        ],
        companyShortName: [
          { required: true, message: '企业名称不能为空', trigger: 'blur' }
        ],
        companyLogo: [
          {
            required: true,
            message: '企业logo不能为空',
            trigger: 'change'
          }
        ],
        industryType: [
          {
            type: 'array',
            required: true,
            message: '行业类型不能为空',
            trigger: 'change'
          }
        ],
        introduction: [
          { required: true, message: '企业简介不能为空', trigger: 'blur' }
        ],
        environment: [
          {
            required: true,
            message: '企业环境不能为空',
            trigger: 'blur',
            validator: checkEnvironment
          }
        ],
        companyAddress: [
          {
            required: true,
            validator: checkAddress,
            type: 'array',
            trigger: 'blur'
          },
          {
            required: true,
            validator: checkAddress,
            type: 'array',
            trigger: 'change'
          }
        ]
      },
      isEdit: false,
      authedCompanyList: [],
      openUserDialog: false, // 新建-企业介绍信息
      fullCompanyInfo: null // 企业在后端的完整数据，更新时，把最新的数据覆盖到这里
    }
  },
  computed: {
    ...mapGetters(['roles']),
    isSuperAdmin() {
      return (
        Array.isArray(this.roles) && this.roles.indexOf('super_admin') > -1
      )
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 导出excel数据
    exportData() {
      getCompanyRecommend().then((response) => {
        this.$download.excel(response, '企业信息.xls')
      })
    },
    // 增加新地址
    handleAddAddress() {
      if (this.companyForm.companyAddress.length >= 10) {
        this.$message.warning('最多支持10个地址')
        return
      }
      const newAdd = {
        provienAndcity: [], // 省市
        province: '', // 省份
        city: '', // 城市
        address: '' // 地址
      }
      this.companyForm.companyAddress.push(newAdd)
    },
    // 删除地址
    deleteAdd(index) {
      this.companyForm.companyAddress.splice(index, 1)
    },
    // 地址省市变化,更新省、市字段
    handleCityChange(index) {
      const { provienAndcity } = this.companyForm.companyAddress[index]
      if (Array.isArray(provienAndcity) && provienAndcity.length === 2) {
        this.companyForm.companyAddress[index].province = provienAndcity[0]
        this.companyForm.companyAddress[index].city = provienAndcity[1]
      }
    },
    // 获取企业完整信息
    getCompanyFullInfo(id) {
      return new Promise((resolve, reject) => {
        getCompanyInfo({ id })
          .then((res) => {
            if (res.code === 0 && res.data) {
              this.fullCompanyInfo = res.data
              // 获取企业地址
              try {
                this.fullCompanyInfo.companyAddress = JSON.parse(
                  this.fullCompanyInfo.companyAddress
                )
                this.fullCompanyInfo.companyAddress =
                  this.fullCompanyInfo.companyAddress.filter(
                    (item) => item.city
                  )
              } catch (error) {
                this.fullCompanyInfo.companyAddress = [
                  {
                    provienAndcity: [], // 省市
                    province: '', // 省份
                    city: '', // 城市
                    address: '' // 地址
                  }
                ]
              }
              // 获取行业类型
              try {
                const industryType = JSON.parse(
                  this.fullCompanyInfo.industryType
                )
                this.fullCompanyInfo.industryType = industryType
                this.fullCompanyInfo.industry = industryType
                // if (!this.isAdmin) {
                //   this.fullCompanyInfo.industryType = industryType[1]
                //   this.fullCompanyInfo.industry = industryType[1]
                // }
              } catch (error) {
                this.fullCompanyInfo.industryType = []
                this.fullCompanyInfo.industry = []
              }
              // 获取企业环境 视频、图片
              try {
                const environment = JSON.parse(
                  this.fullCompanyInfo.environment
                )
                /**
           * 企业环境格式
           * {
                "videoList": [
                    {src:"https://demo-oss.oss-cn-beijing.aliyuncs.com/mp4/d6e7ec98e7184a04a135cdfe58d741a6.mp4", updateTime: ''}
                ],
                "imgList": [
                    {src:"https://demo-oss.oss-cn-beijing.aliyuncs.com/png/3c9d378d02704beca4dbd03121be6ddd.png", updateTime: ''}
                ]
            }
           */
                // 文件上传组件要求媒体格式是数组或逗号字符串，[a, b, c],'a,b,c' 这里为了组件回显，做了拼接操作
                if (
                  Array.isArray(environment.videoList) &&
                  environment.videoList.length &&
                  environment.videoList[0]?.src
                ) {
                  this.videoList = environment.videoList
                    .map((item) => item.src)
                    .join(',')
                } else {
                  // hack 兼容老数据没有src的情况，后续更新了也不影响运行
                  this.videoList = environment.videoList.join(',')
                }
                if (
                  Array.isArray(environment.imgList) &&
                  environment.imgList.length &&
                  environment.imgList[0]?.src
                ) {
                  this.imgList = environment.imgList
                    .map((item) => item.src)
                    .join(',')
                } else {
                  // hack 兼容老数据没有src的情况，后续更新了也不影响运行
                  this.imgList = environment.imgList.join(',')
                }
              } catch (error) {
                // 文件上传组件要求媒体格式是数组或逗号字符串，[a, b, c],'a,b,c'，支持空数组
                this.videoList = []
                this.imgList = []
              }
              Object.assign(this.companyForm, this.fullCompanyInfo)
              this.companyForm.companyId = this.fullCompanyInfo.id
              resolve()
            }
          })
          .catch(() => {
            reject()
          })
      })
    },
    reviewTagChange(data) {
      const index = Number(data.index)
      if (index === 0) {
        this.$refs.WebReview.stopVideo()
      } else {
        this.$refs.PcReview.stopVideo()
      }
    },
    async openEdit(row) {
      await this.getCompanyFullInfo(row.id)
      this.isEdit = true
      this.openUserDialog = true
      this.getAuthedCompanyList()
      setTimeout(() => {
        this.$refs.companyForm.clearValidate()
      }, 20)
    },
    // 点击企业标题，预览企业介绍信息
    async reviewDetail(row) {
      await this.getCompanyFullInfo(row.id)
      this.initReviewDialog()
    },
    // 初始化预览弹窗
    initReviewDialog() {
      this.reviewCompanyDialog = true
      setTimeout(() => {
        this.$refs.PcReview.init(this.companyForm)
        this.$refs.WebReview.init(this.companyForm)
      }, 0)
    },
    // 企业行业类型修改
    businessAreaChange(value) {
      this.companyForm.industryType = value
    },
    // 获取认证公司列表
    getAuthedCompanyList() {
      // getAuthedCompany 编辑-带有企业介绍信息的数据， getAuthedNoRecommendCompany 新增-不带企业介绍信息的数据
      const handle = this.isEdit
        ? getAuthedCompanyList
        : getAuthedNoRecommendCompany
      handle().then((res) => {
        if (res.code === 0 && res.data) {
          this.authedCompanyList = [...res.data]
        }
      })
    },
    // 新建、编辑，点击预览企业（此时的companyForm已经合并过数据了，直接打开）
    reviewCompany() {
      this.$refs.companyForm.validate((boo) => {
        console.log('预览>>>', boo)
        if (boo) {
          this.initReviewDialog()
        }
      })
    },
    /** 查询列表 */
    getList() {
      this.loading = true
      // 处理查询参数
      const params = deepClone({ ...this.queryParams, ...this.setTopParams })
      for (const key in params) {
        if (params[key] === '' || params[key] === null) {
          delete params[key]
        }
      }
      for (const key in params) {
        if (params[key] === null || params[key] === '') {
          delete params[key]
        }
      }
      // 1 按企业热度排序， 2 按最近登录时间排序，3 发布职位数量由高到低， 4 发布职位数量由低到高
      const rangType = Number(params.rangType)
      switch (rangType) {
        //  ascending: 'asc',
        // descending: 'desc'
        case 1:
          params.sortField = {
            field: 'companyHot',
            order: 'desc'
          }
          break
        case 2:
          params.sortField = {
            field: 'lastloginTime',
            order: 'desc'
          }
          break
        case 3:
          params.sortField = {
            field: 'jobCount',
            order: 'desc'
          }
          break
        case 4:
          params.sortField = {
            field: 'jobCount',
            order: 'asc'
          }
          break
      }
      delete params.rangType
      // 执行查询
      getHireCompanyList(params).then((response) => {
        this.list = response.data.list
        this.total = response.data.total
        this.loading = false
      })
    },
    // 新建/编辑-提交企业介绍信息（企业都有信息，不管是新建、编辑，都调用更新接口，企业个人信息、企业介绍信息在同一张表里的）
    submitCompanyForm() {
      this.$refs.companyForm.validate((boo) => {
        if (boo) {
          const params = JSON.parse(JSON.stringify(this.companyForm))
          const industry = JSON.stringify(params.industry)
          params.companyAddress = JSON.stringify(params.companyAddress)
          params.industry = industry
          params.industryType = industry
          updateCompany(params).then((res) => {
            if (res.code === 0 && res.data) {
              this.$message.success('操作成功')
              this.openUserDialog = false
              this.getList()
            }
          })
        }
      })
    },
    /** 取消按钮 */
    cancel() {
      this.openUserDialog = false
      this.reset()
    },
    /** 表单重置 */
    reset() {
      this.companyForm = this.$options.data().companyForm
      this.videoList = ''
      this.imgList = ''
      setTimeout(() => {
        this.$refs.companyForm.clearValidate()
      }, 20)
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRangeCreateTime = []
      this.setTopParams = {}
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.isEdit = false
      this.openUserDialog = true
      this.getAuthedCompanyList()
      this.reset()
      this.title = '新建企业信息'
    },

    handlesetTopSorting() {
      this.$refs.setSortList &&
        this.$refs.setSortList.open({ pageType: 'com' })
    },
    /** 更新招聘企业状态 */
    handleUpdate(row, key, value) {
      const params = {}
      params.id = row.id
      params[key] = value
      if (key === 'setTopInList') {
        setCompanyTopInList({ id: row.id }).then((res) => {
          if (res.code === 0 && res.data) {
            this.getList()
            this.$message.success('操作成功')
          }
        })
      } else if (key === 'topStatus') { // 逻辑废弃
        setCompanyTopStatus(params).then((res) => {
          if (res.code === 0 && res.data) {
            this.getList()
            this.$message.success('操作成功')
          }
        })
      } else {
        modefyCompanyStatus(params).then((res) => {
          if (res.code === 0 && res.data) {
            this.getList()
            this.$message.success('操作成功')
          }
        })
      }
    },
    async handleSetingTopPop(row) {
      const formConfig = [
        {
          type: 'radio',
          value: row.isHot,
          label: '纳入热门企业置顶',
          keyIndex: 'isHot',
          span: 24,
          options: [
            {
              value: 1,
              label: '是'
            },
            {
              value: 0,
              label: '否'
            }
          ]
        },
        {
          type: 'radio',
          value: row.isNew,
          label: '纳入最新企业置顶',
          keyIndex: 'isNew',
          span: 24,
          options: [
            {
              value: 1,
              label: '是'
            },
            {
              value: 0,
              label: '否'
            }
          ]
        }
      ]
      this.$refs.setTop &&
        this.$refs.setTop.open({
          tableData: [
            {
              ...row,
              name: row.companyName
            }
          ],
          formConfig,
          pageType: 'com'
        })
    },
    // 设置置顶确认
    async handleSetTopConfirm({ tableData, isNew, isHot, done }) {
      const { code, msg } = await updateRankingStatus({
        id: tableData[0].id,
        isNew,
        isHot
      })
      if (code !== 0) {
        this.$message.error(msg)
        return
      }
      this.$message.success('设置成功')
      done()
      this.handleQuery()
    }
  }
}
</script>
<style lang="scss" scoped>
.hire-company-page {
  .choose-top-box {
    .el-form-item__label {
      line-height: 1;
    }
  }
}
</style>
<style lang="scss" scoped>
.company-name {
  font-size: 14px;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #37383d;
  line-height: 20px;
  text-align: left;
}
.hight-light {
  color: #1890ff;
  cursor: pointer;
}
.row1 {
  height: 30px;
  line-height: 30px;
  text-align: left;
  img {
    vertical-align: middle;
    margin: 0 10px;
  }
}
</style>
